package com.singzi.leetcode.jianzhiOffer;

import com.singzi.leetcode.obj.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class T0032_2 {
}
class Solution0032_2 {
    List<List<Integer>> list = new ArrayList<>();
    public List<List<Integer>> levelOrder(TreeNode root) {
        addTree(root, 0);
        return list;
    }
    public void addTree(TreeNode treeNode,int k){
        if(list.size()<=k)list.add(new ArrayList<>());
        list.get(k).add(treeNode.val);
        if(treeNode.left != null) addTree(treeNode.left, k+1);
        if(treeNode.right != null) addTree(treeNode.right, k+1);

    }

}